package yamen.bdwm.thread;

import yamen.bdwm.R;
import yamen.bdwm.compatible.ActionBarActivity;
import yamen.bdwm.data.interfaces.onListRefreshedListener;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;

public class ThreadFragment extends Fragment implements onListRefreshedListener {
	Thread thread;
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState)
	{
		View v;
		v= inflater.inflate(R.layout.thread, container,false);
		
		thread=new Thread(getArguments().getString("url"));
		thread.CreateAdapter(0, R.layout.thread_content_item);
		ListView lv=((ListView)v.findViewById(R.id.thread_content_lv));
		lv.setAdapter(thread.getAdapter(0, getActivity()));
		((ActionBarActivity)this.getActivity()).SetRefreshingDialog(true);
		thread.getMore(this);
		
		
		
		return v;
	}
	void getRefreshed()
	{
		((ActionBarActivity)this.getActivity()).SetRefreshingDialog(true);
		
		thread.getRefreshed(0, this);
	}
	public void showReply()
	{
		LinearLayout ll = (LinearLayout) getActivity().findViewById(R.id.reply_ll);
		ll.setVisibility(View.VISIBLE);
	}
	public void hideReply()
	{
		LinearLayout ll = (LinearLayout) getActivity().findViewById(R.id.reply_ll);
		ll.setVisibility(View.GONE);
	}
	public void onRefreshed(int numberOfRefreshed) {
		if((ActionBarActivity)getActivity()!=null)
		((ActionBarActivity)getActivity()).SetRefreshingDialog(false);

	}
	
	public void onError(int i) {
		((ActionBarActivity)getActivity()).SetRefreshingDialog(false);
	}
}
